﻿{include file="base/_meta" /}
</head>
<body>


<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline mr0">
                            <input name="name" class="layui-input" type="text" placeholder="输入名称" autocomplete="off"/>
                        </div>
                    </div>
                    <div class="layui-inline ">
                        <button class="layui-btn icon-btn" lay-filter="formSubSearchUser" lay-submit>
                            <i class="layui-icon">&#xe615;</i>搜索
                        </button>
                        <button id="btnAddUser" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                    </div>
                </div>
            </div>

            <table class="layui-table" id="KT_table" lay-filter="KT_table"></table>
        </div>
    </div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="tableBarUser">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-xs" lay-event="power">权限管理</a>
</script>
<!-- js部分 -->
{include file="base/_script" /}
<script>
    layui.use(['layer', 'form', 'table', 'util', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;

        // 渲染表格
        var KT_table = table.render({
            elem: '#KT_table',
            url: "{:url('/auth/adminRoleList')}",
            page: true,
            cellMinWidth: 100,
            cols: [[
                {field: 'id', title: 'ID'},
                {field: 'name', title: '名称'},
                {field: 'remark', title: '备注'},
                {align: 'center', toolbar: '#tableBarUser', title: '操作', minWidth: 200}
            ]]
        });

        // 添加
        $('#btnAddUser').click(function () {
            add("添加","adminRoleForm")
        });

        // 搜索
        form.on('submit(formSubSearchUser)', function (data) {
            KT_table.reload({where: data.field}, 'data');
        });

        // 工具条点击事件
        table.on('tool(KT_table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'edit') { // 修改
                add("修改","adminRoleForm?id="+data.id)
            } else if (layEvent === 'del') { // 删除
                layer.confirm('确定要删除吗？', {
                    skin: 'layui-layer-admin',
                    shade: .1
                }, function (index) {
                    $.post("{:url('/auth/adminRoleDel')}",{id:data.id},function (ret) {
                        if (ret.code == 0){
                            layer.msg(ret.msg,{icon:6,time:1500},function () {
                                KT_table.reload();
                            })
                        }else{
                            layer.msg(ret.msg,{icon:5,time:1500})
                        }
                    });
                });
            } else if (layEvent === 'power') {
                add("权限管理","adminRolePower?id="+data.id)
            }
        });
    });
</script>

</body>
</html>
